package com.chao.gulimall.ssoserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CheckController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @ResponseBody
    @RequestMapping("/check/{token}")
//    public String check(@RequestParam(value = "token",required = true) String token){
//    public String check(@PathParam(value = "token") String token){
    public String check(@PathVariable(value = "token") String token){

        if(!StringUtils.isEmpty(token)){
            String res = stringRedisTemplate.opsForValue().get(token);
            System.out.println("Res 校验账号密码为："+res);
            if(!StringUtils.isEmpty(res)){
                return "ok";
            }else{
                return "notfound";
            }

        }else {
            return "token is empty";
        }

    }
}
